package com.zw.goodsservice.service;

import com.zw.goodsservice.common.constant.TypeNameEnum;
import com.zw.goodsservice.entity.GoodsInfo;
import com.zw.goodsservice.repository.GoodsInfoRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class GoodsInfoService {

    private final GoodsInfoRepository goodsInfoRepository;


    public GoodsInfo getGoodsInfoById(String id) {
        Optional<GoodsInfo> optional = goodsInfoRepository.findById(id);
        return optional.orElse(null);
    }

    public void addGoodsInfo(GoodsInfo goodsInfo) {
        goodsInfo.setTypeName(TypeNameEnum.getName(goodsInfo.getType()));
        goodsInfo.setDelFlag(0);
        goodsInfo.setCreateTime(LocalDateTime.now());
        goodsInfo.setUpdateTime(LocalDateTime.now());
        goodsInfoRepository.save(goodsInfo);
    }
}
